def times = []
def movingAverages = []

//Ignores type for now: TODO
movingAverage = {ln, window , type, membershipFunction ->
        ln -> if ( membershipFunction(ln)) {
		def matcher = ln =~ /[\[]([^\]]*)[\]]/
		if(matcher)
		{
			sdate = matcher[0][1]
			formatter = new java.text.SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss z"); 
			def date = (Date)formatter.parse(sdate) 
			if(times.size() == 0)
			{
				times << date.getTime()
			}else
			{
				newTime = date.getTime()
				while(times.size() > 0 && newTime-times[0] > window)
				{
					times.remove(0);
				}
				times<<newTime
				if(times.size() > 1)
				{
					def deltaTime = newTime - times[0]
					if(deltaTime)
						movingAverages << times.size()*1000/deltaTime
				}
			}
		}
        }
}

//Ignore type for now
movingAverageResult = { type ->
        movingAverages
}
